﻿//mountDetect.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using System.Diagnostics;

using Styx;
using Styx.Logic;
using Styx.Helpers;
using Styx.Plugins.PluginClass;
using Styx.WoWInternals;

namespace mountDetect
{
    class mountDetect : HBPlugin
    {
        //settings
        private bool _adjustMountSettings = true;
        private bool _forceToMount = true;
        private bool _changeMount = true;
        private int _interval = 10; //change mount every x minutes

        //dont edit below!
        private bool _firstPulse = true;
        private ArrayList _basicGroundMounts = new ArrayList();
        private ArrayList _epicGroundMounts = new ArrayList();
        private string _curMount;
        private Stopwatch _sw = new Stopwatch();
        private readonly Random _rand = new Random(DateTime.Now.Millisecond);
        public override string Name { get { return "[Reputation] Wintersaber Trainers 1.5"; } }
        public override string Author { get { return "kucH3r"; } }
        public override Version Version { get { return new Version(1, 5); } }
        public override bool WantButton { get { return true; } }
		public override void OnButtonPress()
		{
            System.Diagnostics.Process.Start("http://www.panyama.info");
        }
		public override string ButtonText { get { return "www.panYama.info"; } }

        public override void Pulse()
        {
            if (_firstPulse)
            {
                _sw.Start();
                Initialize();
                rndMount();
                _firstPulse = false;
            }

            if (_changeMount && !Styx.WoWInternals.ObjectManager.Me.Combat && _sw.Elapsed.TotalSeconds > 60 * _interval)
            {
                rndMount();
                _sw.Reset();
                _sw.Start();
            }

            if (Mount.CanMount() && !ObjectManager.Me.GotTarget && !ObjectManager.Me.Combat && !ObjectManager.Me.IsIndoors && ObjectManager.Me.IsOutdoors && !ObjectManager.Me.Mounted)
            {
                Mount.StateMount();
                Logging.Write("[mountDetect] mounting up " + LevelbotSettings.Instance.MountName);
            }
            
            if (_forceToMount && Mount.CanMount() && !ObjectManager.Me.GotTarget && !ObjectManager.Me.Combat && !ObjectManager.Me.IsIndoors && ObjectManager.Me.IsOutdoors && !ObjectManager.Me.Mounted)
            {
                Mount.StateMount();
                Logging.Write("[mountDetect] mounting up " + LevelbotSettings.Instance.MountName);
            }
        }

        private void Initialize()
        {
            Logging.Write("[mountDetect] initializing private version for panYama" + Version.ToString());
            int NumCompanions = Convert.ToInt32((Lua.LuaGetReturnValue("return GetNumCompanions(\"MOUNT\")", "mount.lua")[0]));
            Logging.Write("[mountDetect] found " + NumCompanions + " possible mount(s)");
            for (int i = 1; i <= NumCompanions; i++)
            {
                List<string> GetCompanionInfo = Lua.LuaGetReturnValue("return GetCompanionInfo(\"MOUNT\", " + i + ")", "mount.lua");

                string creatureName = GetCompanionInfo[1];
                int creatureSpellID = Convert.ToInt32(GetCompanionInfo[2]);

                if (epicGround.Contains(creatureSpellID))
                {
                    _epicGroundMounts.Add(creatureName);
                }
                else if (basicGround.Contains(creatureSpellID))
                {
                    _basicGroundMounts.Add(creatureName);
                }

                if (_adjustMountSettings && (_epicGroundMounts.Count > 0 || _basicGroundMounts.Count > 0)) LevelbotSettings.Instance.UseMount = true;
                else if (_adjustMountSettings) LevelbotSettings.Instance.UseMount = false;
            }
        }

        public void rndMount()
        {
            if (_epicGroundMounts.Count > 0)
            {
                _curMount = _epicGroundMounts[_rand.Next(0, _epicGroundMounts.Count)].ToString();
                LevelbotSettings.Instance.MountName = _curMount;
                Logging.Write("[mountDetect] using " + _curMount + " now :>");
            }
            else if (_basicGroundMounts.Count > 0)
            {
                _curMount = _basicGroundMounts[_rand.Next(0, _basicGroundMounts.Count)].ToString();
                LevelbotSettings.Instance.MountName = _curMount;
                Logging.Write("[mountDetect] using " + _curMount + " now :>");
            }
        }

        #region mounts
        private int[] epicGround
        {
            get
            {
                return new int[] {
            68057,68056,67466,66906,66846,66091,66090,65646,65645,65644,
			65643,65642,65641,65640,65639,65638,65637,64659,64656,63643,
			63642,63641,63640,63639,63638,63637,63636,63635,63232,61470,
			61469,61467,61465,61447,61425,60424,60119,60118,60116,60114,
			59799,59797,59793,59791,59788,59785,55531,54753,51412,49379,
			49322,48778,48027,46628,43900,43688,42777,41252,39319,39318,
			39317,39316,39315,36702,35714,35713,35712,35028,35027,35025,
			34899,34898,34897,34896,34790,34767,33660,26656,24252,24242,
			23510,23509,23338,23252,23251,23250,23249,23248,23247,23246,
			23243,23242,23241,23240,23239,23238,23229,23228,23227,23225,
			23223,23222,23221,23219,23214,23161,22724,22723,22722,22721,
			22720,22719,22718,22717,18992,18991,17481,17465,17461,17460,
			17459,17450,17229,16084,16083,16082,16081,16080,16056,16055,
			15779
            };
            }
        }

        private int[] basicGround
        {
            get
            {
                return new int[] {
            66847,64977,64658,64657,43899,42776,35711,35710,35022,35020,
			35018,34795,34769,34406,18990,18989,17464,17463,17462,17454,
			17453,13819,10969,10873,10799,10796,10793,10789,8395,8394,
			6899,6898,6777,6654,6653,6648,5784,580,472,470,458
            };
            }
        }
        #endregion
    }
}